Skip to content

Comments

fix(plugin): add .js extensions to ESM imports#8007

Open
derekross wants to merge 1 commit intoanomalyco:devfrom
derekross:fix/plugin-esm-imports
Open

fix(plugin): add .js extensions to ESM imports#8007
derekross wants to merge 1 commit intoanomalyco:devfrom
derekross:fix/plugin-esm-imports

Conversation

@derekross
Copy link

Summary

Fixes the @opencode-ai/plugin package so it works when installed from npm.

Problem

The plugin package fails to load with error:

Cannot find module './tool' imported from .../node_modules/@opencode-ai/plugin/dist/index.js

Root causes:

  1. package.json exports pointed to ./src/index.ts but only dist/ is published to npm
  2. Compiled dist/index.js had export * from "./tool" without .js extension, which does not resolve in Node.js ESM

Solution

  1. Updated package.json exports to point to dist/*.js files with proper ESM conditional exports
  2. Added .js extensions to all relative imports in source files

Testing

Tested with opencode-shakespeare-plugin which was unable to load until this fix was applied.

Fixes #8006

The @opencode-ai/plugin package fails to load when installed from npm because:

1. package.json exports pointed to ./src/index.ts but only dist/ is published
2. Compiled dist/index.js had 'export * from "./tool"' without .js extension

This fix:
- Updates package.json exports to point to dist/*.js files
- Adds .js extensions to all relative imports in source files

Fixes anomalyco#8006
@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

"type": "module",
"license": "MIT",
"scripts": {
"typecheck": "tsgo --noEmit",
"build": "tsc"
},
"exports": {
".": "./src/index.ts",
"./tool": "./src/tool.ts"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't need to be changed because they get rewritten automatically by the publish script.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@derekcross can you followup on that?
That issue is not allowing me to use some plugins - I'd like to get it fixed ;), I can open my PR but I think it's better to update this one.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@derekcross can you followup on that?
That issue is not allowing me to use some plugins - I'd like to get it fixed ;), I can open my PR but I think it's better to update this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@opencode-ai/plugin: ESM imports missing .js extension breaks plugin loading

3 participants